const Koa = require('koa')
const userRouter = require('../router/user')
const { koaBody } = require('koa-body');
const koaStatic = require('koa-static')
const path = require("path");

const app = new Koa()

// console.log(path.join(__dirname, '../../public/upload'))

app.use(koaBody({
    multipart: true,
    formidable: {
        // 这里最好不使用相对路径 因为这里的相对路径是相对 process.cwd()
        // uploadDir: './public/upload',
        uploadDir: path.join(__dirname, '../../public/upload'),
        keepExtensions: true // 保留文件后缀
    }
}))
app.use(koaStatic(path.join(__dirname, '../../public/upload')))
app.use(userRouter.routes())

module.exports = app
